<?php
namespace App\Services;

use App\Models\Ad;
use App\Models\AdPosition;
use Illuminate\Support\Facades\DB;

/**
 *
 * 推荐管理服务层
 *
 * @author manong
 *
 */
class LayoutRecommendService extends BaseService {

    /**
     * 乡粉分享
     *
     * @param $city 城市
     * @param $level 获取等级
     * @param $firstrow
     * @param $pagesize
     * @return array
     */
    public function getLayoutRecommends($province,$city,$country,$firstrow,$pagesize){

        $query = DB::table('layout_recommend');

        if($province){
            $query->where('province',$province);
        }
        if($city){
            $query->where('city',$city);
        }
        if($country){
            $query->where('country',$country);
        }
        $datas = $query->skip($firstrow)->take($pagesize)->get();

        if($datas){
            foreach($datas as $item){
                $item->recom_time_formatted= local_date_ymd($item->recom_time);
                $item->recom_pic = complete_url($item->recom_pic);
                $item->recom_subtitle = trim(str_replace(',', ' ', $item->recom_subtitle));
            }
        }
        // dd($datas);

        return $this->success($datas);

    }

}